package com.sjx.onelinecord

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class AddressBookAdapter(private val list: List<AddressBook>) :
        RecyclerView.Adapter<AddressBookAdapter.ViewHolder>() {

    inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val displayName: TextView = view.findViewById(R.id.displayName)
        val number: TextView = view.findViewById(R.id.number)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(parent.context)
                .inflate(R.layout.address_book_item, parent, false)
        return ViewHolder(view)
    }

    override fun getItemCount(): Int = list.size

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val addressBook = list[position]
        holder.displayName.text = addressBook.displayName
        holder.number.text = addressBook.number
    }
}